package com.nit.lab.mapper.basic;

import com.nit.lab.dto.basic.WjmDTO;
import com.nit.lab.entity.basic.WjmEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface WjmMapper {

    /**
     * @Description: 获取表格数据，查询条件自行编写对应代码，需区分模糊和相等，排序条件无需改动
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Select({"<script>SELECT " +
            "wjm_id AS `key`, wjm_id, " +
            "wjm_name, wjm_tel, wjm_info " +
            "FROM tb_wjm " +
            "WHERE TRUE " +
            "<if test='wjmName != null'> AND wjm_name LIKE CONCAT('%', #{wjmName}, '%') </if>" +
            "<if test='wjmTel != null'> AND wjm_tel LIKE CONCAT('%', #{wjmTel}, '%') </if>" +
            "ORDER BY " +
            "<if test='sortField != null'>" +
            "${sortField} ${sortOrder}, " +
            "</if>" +
            "wjm_id desc " +
            "LIMIT #{start}, #{length}" +
            "</script>"})

    List<WjmDTO> list4Table(
            @Param("start") Integer start,
            @Param("length") Integer length,
            @Param("wjmName") String wjmName,
            @Param("wjmTel") String wjmTel,
            @Param("sortField") String sortField,
            @Param("sortOrder") String sortOrder) throws Exception;
    /**
     * @Description: 获取表格数据记录的总条数
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Select({"<script>SELECT COUNT(*) " +
            "FROM tb_wjm " +
            "WHERE TRUE " +
            "<if test='wjmName != null'> AND wjm_name LIKE CONCAT('%', #{wjmName}, '%') </if>" +
            "<if test='wjmTel != null'> AND wjm_tel LIKE CONCAT('%', #{wjmTel}, '%') </if>" +
            "</script>"})
    Long count4Table(
            @Param("wjmName") String wjmName,
            @Param("wjmTel") String wjmTel) throws Exception;

    /**
     * @Description: 新增记录
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Insert("INSERT INTO tb_wjm (" +
            "wjm_name, wjm_tel, wjm_info )" +
            "VALUES (#{wjmEntity.wjmName}, #{wjmEntity.wjmTel}, " +
            "#{wjmEntity.wjmInfo})")
    @Options(useGeneratedKeys = true, keyProperty = "wjmId", keyColumn = "wjm_id")
    Integer add(@Param("wjmEntity") WjmEntity wjmEntity) throws Exception;

    /**
     * @Description: 更新记录
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Update("UPDATE tb_wjm set " +
            "wjm_name = #{wjmEntity.wjmName}, " +
            "wjm_tel = #{wjmEntity.wjmTel}, " +
            "wjm_info = #{wjmEntity.wjmInfo} " +
            "WHERE wjm_id = #{wjmEntity.wjmId}")
    Integer update(@Param("wjmEntity") WjmEntity wjmEntity) throws Exception;


    /**
     * @Description: 删除记录
     * @Author: SN
     * @Date: 2019/01/30 18:15
     */
    @Delete("DELETE FROM tb_wjm WHERE wjm_id = #{wjmId}")
    Integer remove(@Param("wjmId") Long wjmId) throws Exception;

}
